<?php
/**
 * Displays edit form for a particular extension. Changes are saved
 * to saveextension.php.
 * @copyright &copy; 2006 The Open University
 * @author s.marshall@open.ac.uk
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
 * @package resourcepage
 *//** */

require_once("module_resourcepage.php");
$module=module_resourcepage::$inst;
 
$id=required_param('id',PARAM_INT);    // Course Module ID
$extension=required_param('extension',PARAM_ALPHA);
$scrollpos=optional_param('scrollpos',0,PARAM_INT);

$module->obtain_view_info($id,null,$cm,$course,$resourcepage);

// Security checks
$module->verify_edit_action($cm);

// Get extension object
$extobj =& $module->get_specified_extension($extension);
$pullextension=is_a($extobj,'resourcepage_extension_pull');

if($pullextension) {
    $mode=required_param('mode',PARAM_ALPHA);
    if($mode!='add') {
        $container=required_param('container',PARAM_INT);
    }
    $title=get_string($mode=='add' ? 'addinganew' : 'editinga','',
        $extobj->get_display_name()); 
} else {
    $mode='edit';
    $placeholderitemid=required_param('placeholderitemid',PARAM_INT);
    $placeholder=required_param('placeholder',PARAM_ALPHA);
    $title=get_string('editinga','',
        $extobj->get_placeholder_title($placeholder,$placeholderitemid)); 
}

// Show header
$module->print_header($cm,$course,$resourcepage,$title,false);

// Check HTML editor (code similar to that in mod.php) 
if ($usehtmleditor = can_use_html_editor()) {
    $defaultformat = FORMAT_HTML;
    $editorfields = '';
} else {
    $defaultformat = FORMAT_MOODLE;
}

print_heading_with_help($title, "mods", 'resourcepage_'.$extension);
print_simple_box_start('center', '', '', 5, 'generalbox', 'resourcepage_'.$extension);

if($pullextension) {
    $extobj->show_edit_form($mode=='add' ? 0 : $container,$course,$cm,array('scrollpos'=>$scrollpos));
} else {
    $extobj->show_edit_form($course,$placeholderitemid,$cm,array('scrollpos'=>$scrollpos));
}
print_simple_box_end();
?>
